﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using IterationLife.System.Models;
using Util.Domains;

namespace IterationLife.UserProfiles.Models {
    /// <summary>
    /// 用户亲属
    /// </summary>
    [Description( "用户亲属" )]
    public partial class UserRelative : AggregateRoot<UserRelative>,IDelete {
        /// <summary>
        /// 初始化用户亲属
        /// </summary>
        public UserRelative() : this( Guid.Empty ) {
        }

        /// <summary>
        /// 初始化用户亲属
        /// </summary>
        /// <param name="id">用户亲属标识</param>
        public UserRelative( Guid id ) : base( id ) {
        }

        /// <summary>
        /// 用户编号
        /// </summary>
        [Required(ErrorMessage = "用户编号不能为空")]
        public Guid UserId { get; set; }
        /// <summary>
        /// 用户资料编号
        /// </summary>
        [Required(ErrorMessage = "用户资料编号不能为空")]
        public Guid UserProfileId { get; set; }
        /// <summary>
        /// 关系
        /// </summary>
        [StringLength( 50, ErrorMessage = "关系输入过长，不能超过50位" )]
        public string Relationship { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreationTime { get; set; }
        /// <summary>
        /// 是否删除
        /// </summary>
        [Required(ErrorMessage = "是否删除不能为空")]
        public bool IsDeleted { get; set; }
        
        /// <summary>
        /// 用户资料
        /// </summary>
        public virtual UserProfile UserProfile { get; set; }
        
        /// <summary>
        /// 用户
        /// </summary>
        public virtual User User { get; set; }
        
        /// <summary>
        /// 添加描述
        /// </summary>
        protected override void AddDescriptions() {
            AddDescription( "用户亲属编号", Id );
            AddDescription( "用户编号", UserId );
            AddDescription( "用户资料编号", UserProfileId );
            AddDescription( "关系", Relationship );
            AddDescription( "创建时间", CreationTime );
        }
        
        /// <summary>
        /// 添加变更列表
        /// </summary>
        protected override void AddChanges( UserRelative newEntity ) {
            AddChange( "Id", "用户亲属编号", Id, newEntity.Id );            
            AddChange( "UserId", "用户编号", UserId, newEntity.UserId );
            AddChange( "UserProfileId", "用户资料编号", UserProfileId, newEntity.UserProfileId );
            AddChange( "Relationship", "关系", Relationship, newEntity.Relationship );
            AddChange( "CreationTime", "创建时间", CreationTime, newEntity.CreationTime );
        }
    }
}